// pages/index/listQuery/result/result.js
const app = getApp();
const util = require("../../../../utils/util");
let attrList;
let toggleCollection = true;
Page({
    data: {
        results: [],
        scroll: false,
    },

    onLoad: function(options) {
        // util.colleation(this, "名单查询");
        toggleCollection = true;
        attrList = JSON.parse(options.attr);
        util.getUrl(app.globalData.url).then(res => {
            let $getSelectResult = {
                ac: 'attr',
                model_id: options.modelId,
                data: JSON.stringify(attrList),
            };
            let apiUrl = 'listQuery.php';
            if (options.modelId === '1') {
                apiUrl = 'yaohao.php';
                $getSelectResult.ac = 'yaohao';
                $getSelectResult['city'] = options.cityName;
                delete $getSelectResult.model_id;
            } else if (options.modelId === '2') {
                $getSelectResult.ac = 'fangjia';
                $getSelectResult['city'] = options.cityName;
            }
            util.bstrequest(`${apiUrl}`, $getSelectResult, 'POST').then(res => {
                let results = JSON.parse(JSON.stringify(res.data.data));
                if (Array.isArray(results))
                    results = ''
                else
                    for (let attrId in results) {
                        for (let attr in results[attrId]) {
                            if (results[attrId][attr])
                                results[attrId]['show'] = true;
                            else
                                results[attrId]['show'] = false;
                        }
                    }
                this.setData({
                    results: results
                });
            });
        });
    },

    backBtn: function() {
        wx.navigateBack({

        })
    },
    onPageScroll() {
        if (toggleCollection) {
            this.setData({
                scroll: true,
            });
            toggleCollection = false;
        }

    },
    closeCollection() {
        toggleCollection = false;
    },
    openCollection() {
        toggleCollection = true;
    }
})